package com.example.foobar.controller;

import com.example.foobar.business.service.DidiOrderService;
import com.example.foobar.entity.DidiOrders;
import lombok.extern.slf4j.Slf4j;
import com.example.foobar.param.DidiOrdersPageParam;
import io.geekidea.springbootplus.framework.common.controller.BaseController;
import io.geekidea.springbootplus.framework.common.api.ApiResult;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.log.annotation.Module;
import io.geekidea.springbootplus.framework.log.annotation.OperationLog;
import io.geekidea.springbootplus.framework.log.enums.OperationLogType;
import io.geekidea.springbootplus.framework.core.validator.groups.Add;
import io.geekidea.springbootplus.framework.core.validator.groups.Update;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 滴滴订单 控制器
 *
 * @author 郑英奔
 * @since 2021-10-26
 */
@Slf4j
@RestController
@RequestMapping("/didiOrders")
@Module("foobar")
@Api(value = "滴滴订单API", tags = {"滴滴订单"})
public class DidiOrdersController extends BaseController {

    @Autowired
    private DidiOrderService didiOrderService;

    /**
     * 添加滴滴订单
     */
    @PostMapping("/add")
    @OperationLog(name = "添加滴滴订单", type = OperationLogType.ADD)
    @ApiOperation(value = "添加滴滴订单", response = ApiResult.class)
    public ApiResult<Boolean> addDidiOrders(@Validated(Add.class) @RequestBody DidiOrders didiOrders) throws Exception {
        boolean flag = didiOrderService.saveDidiOrders(didiOrders);
        return ApiResult.result(flag);
    }

    /**
     * 修改滴滴订单
     */
    @PostMapping("/update")
    @OperationLog(name = "修改滴滴订单", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改滴滴订单", response = ApiResult.class)
    public ApiResult<Boolean> updateDidiOrders(@Validated(Update.class) @RequestBody DidiOrders didiOrders) throws Exception {
        boolean flag = didiOrderService.updateDidiOrders(didiOrders);
        return ApiResult.result(flag);
    }

    /**
     * 删除滴滴订单
     */
    @PostMapping("/delete/{id}")
    @OperationLog(name = "删除滴滴订单", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除滴滴订单", response = ApiResult.class)
    public ApiResult<Boolean> deleteDidiOrders(@PathVariable("id") Long id) throws Exception {
        boolean flag = didiOrderService.deleteDidiOrders(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取滴滴订单详情
     */
    @GetMapping("/info/{id}")
    @OperationLog(name = "滴滴订单详情", type = OperationLogType.INFO)
    @ApiOperation(value = "滴滴订单详情", response = DidiOrders.class)
    public ApiResult<DidiOrders> getDidiOrders(@PathVariable("id") Long id) throws Exception {
        DidiOrders didiOrders = didiOrderService.getById(id);
        return ApiResult.ok(didiOrders);
    }

    /**
     * 滴滴订单分页列表
     */
    @PostMapping("/getPageList")
    @OperationLog(name = "滴滴订单分页列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "滴滴订单分页列表", response = DidiOrders.class)
    public ApiResult<Paging<DidiOrders>> getDidiOrdersPageList(@Validated @RequestBody DidiOrdersPageParam didiOrdersPageParam) throws Exception {
        Paging<DidiOrders> paging = didiOrderService.getDidiOrdersPageList(didiOrdersPageParam);
        return ApiResult.ok(paging);
    }

}

